package pers.cz.netty.filter;

/**
 * @version 1.0
 * @description:
 * @author: ChengZhi 0336
 * @create: 2024-08-12 12:13
 **/
public abstract class AbstractFilterHandlerContext<T, O> implements FilterHandlerContext<T,O>{

    private final Pipeline<T,O> pipeline;

    volatile AbstractFilterHandlerContext<T,O> prev;

    volatile AbstractFilterHandlerContext<T,O> next;

    public AbstractFilterHandlerContext(Pipeline<T,O> pipeline) {
        this.pipeline = pipeline;
    }

    protected abstract FilterHandler<T,O> handler();

    protected final AbstractFilterHandlerContext<T,O> findNextCtx() {
        return next;
    }

    protected  final AbstractFilterHandlerContext<T,O> findPrevCtx() {
        return prev;
    }

    @Override
    public Pipeline<T,O> pipeline() {
        return pipeline;
    }

    @Override
    public boolean doFilter(T t1, O o1) {
        return handler().approve(t1, o1, findNextCtx());
    }
}
